<?php 
	include('template/header.php');
	include('classess/user_subscribe.php');
	include('classess/user_affiliate.php');
	$usr = new User_affiliate();
	if(isset($_POST['aff_user_name'])){
		$usr_info = $usr->saveSubscribeInfo();		
	}
?>
<style>
	.right_container{
		margin-top:70px !important;
	}
</style>
	<section  class="homepage-slider" id="home-slider">
		<div class="flexslider">
			<ul class="slides">
				<li>
					<img src="img/slider/first_image.jpg" alt="No Image" />					
				</li>
				<li>
					<img src="img/slider/second_image.jpg" alt="No Image" />					
				</li>
			</ul>
		</div>			
	</section>
	<section class="main-content">
		<div class="row">

			<div class="span9">													
				<div class="row">
					<div class="span9">
						<h4 class="title">
							<span class="pull-left"><span class="text"><span class="line"><strong>Affiliate Subscribe Form</strong></span></span></span>
							<span class="pull-right">
								&nbsp;
							</span>
						</h4>
						<?php 
							if(isset($usr_info)){								
						?>
						<div class="alert alert-error">
							<div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>
							<div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $usr_info; ?></div>
							<div style="clear:both;"></div>							
						</div>
						<?php
							}
						?>
						<div id="myCarousel" class="myCarousel carousel slide">
							<div class="carousel-inner">
								<div class="active item">
									<form action="<?php echo $_SERVER['PHP_SELF']; ?>?af_pr=1" method="POST" name="affiliate_subscribe" >
										<div class="span8">
											<div class="accordion" id="accordion2">					
												<div class="accordion-group">
													<div id="collapseTwo" class="accordion-body collapse in" style="height: auto;">
														<div class="accordion-inner">
															<div class="row-fluid">									
																<div class="span6">								
																
																	<div class="control-group">
																		<label class="control-label">User Name</label>
																		<div class="controls">
																			<input type="text" name="aff_user_name" id="aff_user_name" placeholder="Name" class="input-xlarge" value="">
																		</div>
																	</div>
																	<div class="control-group">
																		<label class="control-label">Email Id</label>
																		<div class="controls">
																			<input type="text" name="aff_user_email" id="aff_user_email" class="input-xlarge" placeholder="Email" required/>
																		</div>
																	</div>
																	<div class="control-group">
																		<label class="control-label">Phone</label>
																		<div class="controls">
																			<input type="text" name="user_phone" id="user_phone" class="input-xlarge" placeholder="Phone" required/>
																		</div>
																	</div>										
																	<div class="control-group">
																		<label class="control-label">City:</label>
																		<div class="controls">
																			<input type="text" name="user_city" id="user_city" class="input-xlarge" placeholder="City" required/>
																		</div>
																	</div>
                                                                                                                                    										
																	<div class="control-group">
																		<label class="control-label">Address:</label>
																		<div class="controls">
																			<input type="text" name="address" id="address" class="input-xlarge" placeholder="Address" required/>
																		</div>
																	</div>
                                                                                                                                    
                                                                                                                                    
																</div>
																<div class="span6">	
																	<div class="control-group">
																		<label class="control-label">State:</label>
																		<div class="controls">
																			<input type="text" name="user_state" id="user_state" placeholder="State" class="input-xlarge" required/>
																		</div>
																	</div>
																	<div class="control-group">
																		<label class="control-label">Zip Code:</label>
																		<div class="controls">
																			<input type="text" name="user_zip" id="user_zip" class="input-xlarge" placeholder="Zip" required/>
																		</div>
																	</div>
																	<div class="control-group">
																		<label class="control-label">Country:</label>
																		<div class="controls">
																			<input type="text" name="user_country" id="user_country" class="input-xlarge" placeholder="Country" required/> 
																		</div>
																	</div>
																	<div class="control-group">
																		<label class="control-label">Web Site URL:</label>
																		<div class="controls">
																			<input type="text" name="web_url" id="web_url" class="input-xlarge" placeholder="Web Site URL" required/> 
																		</div>
																	</div>
																</div>
																<button class="btn btn-inverse pull-right" name="submit_form" id="submit_form">Subscribe</button>
															
															
															</div>
														</div>
													</div>
												</div>					
											</div>
										</div>				
									</form>	
								</div>
							</div>							
						</div>
					</div>						
				</div>	
			</div>

			<?php include('template/right_panel.php'); ?>
		</div>
	</section>
   
<?php include('template/footer.php'); ?>
<script>
	$ = jQuery.noConflict();
	$(document).ready(function(){	
		var regex = /(\d.*){10}/;
		var regex1 = /([^\d]+)/g;
		var phnVal = $('#user_phone').val().replace(regex1,'');
		var number = /(\d)\1{9}/;
		
		

		$('.close').click(function(){
			$('.alert-error').addClass('hide');
		});
		
		
		$('#submit_form').click(function(){
			if($('#aff_user_name').val().trim() == ''){			
				alert("Please enter a value for the \"User Name\" field.");
				$('#aff_user_name').focus();
				return (false);
			}			
			else if($('#aff_user_email').val().trim() == "")
			{
				alert("Please enter a value for the \"Email\" field.");
				$('#aff_user_email').focus();				
				return (false);
			}
			else if(($('#aff_user_email').val().indexOf("\@") == -1) || ($('#aff_user_email').val().indexOf(".")== -1) || isInvalidateEmail($('#aff_user_email').val()))
			{
				alert("Invalid Email Address");
				$('#aff_user_email').focus();
				return (false);
			}
			else if($('#user_phone').val().trim() == ""){
				alert("Please enter a value for the \"User Phone \" field.");
				$('#user_phone').focus();				
				return (false);
			}
			else if(!$('#user_phone').val().match(regex))
			{
				alert("Please enter your complete 10 digit phone number.");
				$('#user_phone').focus();
				return (false);
			} 
			else if(phnVal.match(number))
			{
				alert("Please enter proper 10 digit phone number.");
				$('#user_phone').focus();
				return (false);
			}
			else if($('#user_city').val().trim() == ""){
				alert("Please enter a value for the \"User City \" field.");
				$('#user_city').focus();				
				return (false);
			}
			else if($('#user_state').val().trim() == ""){
				alert("Please enter a value for the \"User State \" field.");
				$('#user_state').focus();				
				return (false);
			}
			else if($('#user_zip').val().trim() == ""){
				alert("Please enter a value for the \"User Zip \" field.");
				$('#user_zip').focus();				
				return (false);
			}			
			else if(isNaN($('#user_zip').val()))
			{
				alert("Please Enter Numeric Code.");
				$('#user_zip').focus();	
				return (false);
			}			
			else if($('#user_country').val().trim() == ""){
				alert("Please enter a value for the \"User Country \" field.");
				$('#user_country').focus();				
				return (false);
			}
			else if($('#web_url').val().trim() == ""){
				alert("Please enter a value for the \"Website URL \" field.");
				$('#web_url').focus();				
				return (false);
			}
			else{
				document.affiliate_subscribe.submit();
			}		

		});
	});
		
	function isInvalidateEmail(str)
	{
		var atpos=str.indexOf("@");
		var dotpos=str.lastIndexOf(".");
		if (atpos<1 || dotpos<atpos+2 || dotpos+2>=str.length)
		  {
		  return true;
		  }
		return false;
	}
</script>
